<template>
	<div class="gk-layout-container">
		<div class="gk-layout-header"> 
			<s-query perms="report:doStat"   @click="findPage" >
				<s-item v-model="filters.itemId"  ></s-item>
				<s-date  :p="filters.b" @dateChange="function(v){filters.b=v}" placeholder="开始时间" />
			    <s-date  :p="filters.e" @dateChange="function(v){filters.e=v}" placeholder="结束时间" />
			</s-query>
		</div>
		<div class="gk-layout-main">
			<my-table :data="pageResult.content"  :loading="loading" >
				<el-table-column :label="$t('action.desc')" width="50" fixed="left"  header-align="center" align="center">
					<template slot-scope="scope">   {{scope.$index+1}}   </template>
				</el-table-column> 
				<column  prop="doType" label="类型" :formatter="selectionFormat" /> 
				<Column  prop="doNo"   label="单号"    />
				<Column  width="300"  prop="itemId" label="物料"    :formatter= "itemFilter"  />
				<Column  prop="batchNo" :label="$t('field.do.batchNo')"    />
				<Column  prop="inCount" label="入库"   />
				<Column  prop="outCount" label="出库"     />
				<Column  prop="remain" label="结余"     /> 
			    <Column  prop="createTime" label="时间"   width="120"  :formatter= "dateFormat" /> 
			</my-table>
		</div> 
		<div class="toolbar gk-layout-footer"  style="padding:10px;">
				<el-pagination layout="total, prev, pager, next, jumper"  @current-change="findPage"
							:current-page="filters.pageNum"
							:page-size="filters.pageSize"
							:total="pageResult.totalSize"
							style="float:right;">
				</el-pagination>
		</div>
	</div>
</template>

<script>

	import KtButton from "@/views/Core/KtButton"
	import { format ,formatDay} from "@/utils/datetime" 
	import Column from "@/views/Core/Column"
	import MyTable from "@/views/Core/MyTable" 
	import SQuery from "@/components/Kj/SQuery"
	import SDict from "@/components/Kj/SDict"
	import SItem from "@/components/Kj/SItem" 
    import SReflash from "@/components/Kj/SReflash"
    import {  dictsFormat ,getItemName} from "@/utils/myUtil" 
	 import SDate from "@/components/Kj/SDate"
	export default {
		components: {
			KtButton,
			Column,
			MyTable,
			SQuery,
			SDict,
			SItem,SReflash,SDate
		},
		data() {
			return { 
				filters: {
					label: '',pageNum: 1, pageSize:this.global.pageSize 
				},
				loading:false, 
				pageResult: {} 
				 
			}
		},
		methods: { 
			findPage: function (data) {
				if(data!=-1){
					data=data||1;
					this.filters.pageNum = data
				}
			 
			 
				this.$api.report.doStatPage(this.filters).then((res) => {
					this.pageResult = res.data
				}) 
			},
		 
		 
			// 时间格式化
			dateFormat: function (row, column, cellValue, index) {
				return formatDay(row[column.property])
			},
			
			countFormat: function (row, column, cellValue, index) { 
				return cellValue +dictsFormat( "units",row.unit)
			}, 
			itemFilter: function (row, column, cellValue, index) {
				return getItemName(cellValue )
			},
		 
			selectionFormat: function (row, column, cellValue, index) {
				let key = "doType"
			 
				return dictsFormat( key,cellValue);
			}
		},
		mounted() {
			this.findPage(1)
		},
		 created () {
   
    	},
	}
</script>

<style scoped>

</style>